import Vue from 'vue'
import Vuex from 'vuex'
import goodList from '@/components/GoodList'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    goodList: [
      {
        name: '诸葛亮',
        price: 1000,
        num: 1,
        checked: false,
      },
      {
        name: '蔡文姬',
        price: 1500,
        num: 1,
        checked: false,
      },
      {
        name: '妲己',
        price: 2000,
        num: 1,
        checked: false,
      },
      {
        name: '鲁班',
        price: 2200,
        num: 1,
        checked: false,
      },
    ],
  },
  getters: {
    allSum: (state) =>
      state.goodList.reduce((sum, obj) => {
        if (obj.checked === true) sum += obj.price * obj.num
        return sum
      }, 0),
  },
  mutations: {},
  actions: {},
  modules: {},
})